layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		layedit = layui.layedit,
		laydate = layui.laydate,
		$ = layui.jquery;
	//加载页面基础信息
	loadStaff();
    
 	form.on("submit(addNews)",function(data){
 		//判断Url地址栏（用于判断本次提交是添加员工还是修改员工）
 		
 		addDepar();
 		
 		/*//弹出loading
 		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        setTimeout(function(){
            top.layer.close(index);
			top.layer.msg("文章添加成功！");
 			layer.closeAll("iframe");
	 		//刷新父页面
	 		parent.location.reload();
        },2000);*/
 		return false;//阻止表单提交
 	})

 	
	//加载本页面初始数据(需要传入部门标识或者职业标识，判断修改时分开加载，因为上面有个部门下拉监听：防止死循环)
 	function loadStaff(){
 			//渲染
	 		form.render();
	 		//得到Url中?后面的字符串
		 	var urlParam = decodeURI(location.search).substring(1);//
		 	//alert(urlParam)
		 	//转化为数组
	 	 	var spurlParamArray = new Array();
	 	 	spurlParamArray = urlParam.split(",");
	 	 	if(urlParam.length>5){//代表是点击修改过来的
	 	 			var dpIid=spurlParamArray[0];
		 	 		var txtdpIduty=spurlParamArray[1];
		 	 		var name=spurlParamArray[2];
		 	 		//赋值
		 	 		$("#dpIid").prop("value",dpIid);
		 	 		$("#inpName").prop("value",name);
		 	 		$("#txtdpIduty").prop("value",txtdpIduty);
	 	 	}
 	}
 	
 	
 	//添加部门(后来添加与修改部门通用)
 	function addDepar(){
 		//top.layer.msg("准备添加部门");
 		//得到表单数据
 		var name = $("#inpName").val();
 		var txtdpIduty = $("#txtdpIduty").val();
 		//得到影藏框是否有id
 		var dpIid = $("#dpIid").val();
 		//alert(siid);
 		//layer.msg(name+"-"+selSex+"-"+inpPhone+"-"+selDepartment+"-"+selPosition+"-"+inpCardId+"-"+txtAddress);
 		if(dpIid==""){//代表添加
 			$.ajax({
 	 			type:"post",
 	 			url:"../departmentinfoAction!addDepartmentinfo",
 	 			data:{name:name,txtdpIduty:txtdpIduty},
 	 			dataType:"text",
 	 			success:function(data){
 	 				if(data.length>20){
 	 					data = "信息重复！"
 	 				}
 	 				var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
 	 				setTimeout(function(){
 	 		            top.layer.close(index);
 	 					top.layer.msg(data);
 	 		 			layer.closeAll("iframe");
 	 			 		//刷新父页面
 	 			 		parent.location.reload();
 	 		        },2000);
 	 			},
 	 			error:function(){
 	 				setTimeout(function(){
 	 		            top.layer.close(index);
 	 					top.layer.msg("网络异常，请重新登录！");
 	 		        },2000);
 	 			}
 	 		});
 		}else{//代表修改
 			//alert("我即将修改该部门");
 			$.ajax({
 	 			type:"post",
 	 			url:"../departmentinfoAction!updateDepar",
 	 			data:{dpIid:dpIid,name:name,txtdpIduty:txtdpIduty},
 	 			dataType:"text",
 	 			success:function(data){
 	 				if(data.length>20){
 	 					data = "信息重复！"
 	 				}
 	 				var index = top.layer.msg('数据修改中，请稍候',{icon: 16,time:false,shade:0.8});
 	 				setTimeout(function(){
 	 		            top.layer.close(index);
 	 					top.layer.msg(data);
 	 		 			layer.closeAll("iframe");
 	 			 		//刷新父页面
 	 			 		parent.location.reload();
 	 		        },2000);
 	 			},
 	 			error:function(){
 	 				alert("网络异常，请重新登录！");
 	 			}
 	 		});
 		}
 	}
});




